#define _CRT_SECURE_NO_WARNINGS
#include "heap.h"

void test1()
{
	heap hp;
	HeapInit(&hp);
	int a[10] = { 3,1,6,4,2,9,7,10,8,5 };
	int i = 0;
	int sz = sizeof(a) / sizeof(a[0]);
	for (i = 0; i < sz; i++)
	{
		HeapPush(&hp, a[i]);
	}
	int size = HeapSize(&hp);
	printf("%d\n", size);
	while (!HeapEmpty(&hp))
	{
		printf("%d\n", HeapTop(&hp));
		HeapPop(&hp, sz);
	}
	HeapDestroy(&hp);
}

void HeapSort(HeapDataType* a,int n)
{
	for (int i = 1; i < n; i++)
	{
		AdjustUp(a, i);
	}

	int end = n - 1;
	while (end > 0)
	{
		Swap(&a[0], &a[end]);
		AdjustDown(a, end, 0);
		end--;
	}
}

void test2()
{
	HeapDataType a[] = { 2,45,1,4,57,6,2,9,1,3 };
	HeapSort(a, sizeof(a) / sizeof(a[0]));
	int i = 0;
	for (i = 0; i < sizeof(a) / sizeof(a[0]); i++)
	{
		printf("%d ", a[i]);
	}
}

int main()
{
	//test1();
	test2();
	return 0;
}